<template>

  <el-dialog title="选择对象" :visible.sync="$attrs.visableIf" @close="handleCloseDialog" :close-on-click-modal="false" :close-on-press-escape="false" append-to-body width="800px">
    <div class="content-big">
      <div class="content-left">
        <div class="title">筛选 <span>清空筛选</span></div>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
          <el-form-item prop="userName1">
            <WeChat
              :options="options"
              @getValue="getValue"
              inputWidth="210px"
              :placeholder="`全部企微号`"
            ></WeChat>
          </el-form-item>
          <el-form-item prop="userName2">
            <div class="search">
              <el-input v-model="queryParams.userName1" size="small" placeholder="关键词搜索" clearable/>
              <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
            </div>
          </el-form-item>
          <el-form-item prop="userName5">
            <div class="right-big">
              <el-select
                v-model="queryParams.userName5"
                @change="handleQuery"
                placeholder="请选择有无备注"
              >
                <el-option
                  v-for="item in callList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item>
            <div class="right-big">
              <el-date-picker
                v-model="dateRange1"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                @change="handleQuery"
                style="width: 100%"
              ></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item prop="userName6">
            <div class="right-big">
              <el-select
                v-model="queryParams.userName6"
                @change="handleQuery"
                placeholder="请选择性别"
              >
                <el-option
                  v-for="item in sexList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item prop="userName6">
            <MultipleSelect size="small" placeholder='企微标签' :receiverNameOpt='lableOpt'/>
          </el-form-item>
          <el-form-item prop="userName5" >
            <div class="right-big"@click.stop="getShowQroup" style="position: relative; z-index: 3; cursor: pointer">
              <el-select
                v-model="queryParams.userName5"
                @change="handleQuery"
                placeholder="按群查找"
                style="position: relative; z-index: -1"
              >
              </el-select>

            </div>
          </el-form-item>
        </el-form>
      </div>
      <div class="content-right">
        <el-table
          :data="tableDataList"
          ref="companylabelList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column
            :label="item.label"
            align="center"
            v-for="(item, index) in tableColumns"
            :key="index"
            :prop="item.key"
            :min-width="item.minWidth ? item.minWidth : ``"
            :fixed="item.fixed ? item.fixed : false"
            :show-overflow-tooltip="true"
          >
            <!--用于表格自定义-->
            <template slot-scope="scope">
              <div v-if="item.key=='name'">
                <div class="userInfo">
                  <img src="../../../assets/images/profile.jpg"/>
                  <div class="name">小城红</div>
                  <div class="label">@志新</div>
                </div>
              </div>
              <div class="label-list" v-else-if="item.key=='label'">
                <label>企业：</label>
                <span>未入VIP群</span>
                <span>持续7天未发言</span>
                <span>1000</span>
              </div>

              <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>


    <div class="footer-btn" slot="footer">
      <div class="number">已选择：<span>0</span>客户
        <el-button>全部选择</el-button>
      </div>
      <el-button @click="handleCloseDialog">取消</el-button>
      <el-button type="primary">提交</el-button>
    </div>
    <searchGroup v-if="showSearchGroup" :visableIf.sync="showSearchGroup"></searchGroup>
  </el-dialog>
</template>

<script>


import {listUser} from "@/api/system/user";
import MultipleSelect from "@/views/components/multipleSelect.vue";
import WeChat from "@/views/components/WeChat.vue";

export default {
  name: 'selectPeople',
  components: {
    WeChat,
    MultipleSelect,
    'searchGroup': () => import('./searchGroup.vue'),//选择群
  },
  data() {
    return {
      // 查询参数
      showSearchGroup: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName1: null,
        userName2: null,
        userName3: null,
        userName4: null,
        userName5: null,
        userName6: null,
        userName7: null,
        userName8: null,
        userName9: null,
        userName10: null,
        userName11: null,
        userName12: null,
        userName13: null,
        userName14: null,
      },
      callList: [
        //称呼
        {id: 1, name: "有"},
        {id: 2, name: "无"},
      ],
      tableColumns: [
        {key: 'name', label: `客户`, visible: true, minWidth: 150, fixed: true},
      ],
      options: [{
        value: 1,
        label: '小红',
        WeChatNum: 2,
        WeChatName: '智行',
      }, {
        value: 2,
        label: '小军',
        WeChatNum: 1,
        WeChatName: '锐行',
      }, {
        value: 3,
        label: '小李',
        WeChatNum: 1,
        WeChatName: '锐行',
      }],
      tableDataList: [],
      lableOpt: [
        {value: 1, label: '客户等级', children: [
            {value: 3, label: '核心',},
            {value: 4, label: '重要',},
            {value: 5, label: '一般',}
          ]
        },
        {value: 2, label: '客户等级2', children: [
            {value: 6, label: '可爱',},
            {value: 7, label: '知性',},
            {value: 8, label: '性感',}
          ]}
      ],
      sexList: [
        //性别
        {id: 1, name: "男"},
        {id: 2, name: "女"},
      ],
      total: 8, // 表格的总条数
      multipleSelection: [],//表格多选
      showSelectSmartTags: false,//智能标签
      tableHeight: 600,
      dateRange1: [],
    }
  },
  created() {
  },
  mounted() {
  },
  watch: {},
  methods: {
    getValue(obj) {
      console.log('获取行', obj);
    },
    getShowQroup() {
      this.showSearchGroup=true;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
        postIds: [],
        roleIds: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        })
        console.log('multipleSelection', this.multipleSelection);
      }
    },
    handleCloseDialog() {
      this.$emit('update:visableIf', false);
      this.$emit('handleQuery');
    }
  }
}
</script>

<style scoped lang="scss">
.number {
  position: absolute;
  left: 10px;
  top: 0px;
  font-size: 14px;

  span {
    color: rgba(0, 0, 0, .65);
    color: rgb(240, 139, 0);
  }

  .el-button {
    color: #3370ff;
    border: none;
  }
}

.footer-btn {
  position: relative;


}

.content-big {
  display: flex;
  height: 100%;

  .content-left {
    width: 250px;
    background: #eee;
    padding: 10px 20px;
  }

  .content-right {
    flex: 1;
  }
}

.el-form {
  .el-form-item {
    margin-bottom: 10px;
    margin-right: 0px;
  }
}

::v-deep .el-dialog__body {
  overflow-y: auto;
  height: 600px;
  padding: 0px;
}

.el-checkbox-group {
  margin-top: 20px;

  .el-checkbox {
    margin-bottom: 12px;
    width: 150px;
  }
}

.title {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  span {
    color: #3370ff;
  }
}

.exclusion {
  margin: 12px 0px;
  padding: 12px 16px;
  border-radius: 2px;
  border: 1px solid #f0f0f0;
}
.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}
</style>
